<template>
    <el-dropdown>
        <el-avatar icon="el-icon-user-solid"></el-avatar>
        <el-dropdown-menu>
            <el-dropdown-item @click.native="getUserInfo">个人信息</el-dropdown-item>
            <el-dropdown-item :loading="loading" @click.native="logout">退出登录</el-dropdown-item>
        </el-dropdown-menu>
    </el-dropdown>
</template>

<script>
export default {
    data() {
        return {
            loading: false
        }
    },
    created() {
    
    },
    methods: {
        getUserInfo() {
            this.$router.push('/personalInformation')
        },
        logout() {
            this.loading = true
            let userId = this.$store.getters.userInfo.id
            this.$store.dispatch('user/logout', userId).then(() => {
                this.$store.commit('course/SET_COURSE', {})
                this.$store.commit('permission/SET_ASYNC_ROUTES', [])
                this.loading = true
                this.$message({
                    message: '已成功退出',
                    type: 'success'
                })
            })
        },
    }
}
</script>

<style lang="scss" scoped>
.el-avatar {
    cursor: pointer;
}
</style>
